package com.eshop.modules.order.service.mapper;

import com.eshop.modules.order.service.dto.ChartDataDto;
import java.util.Date;
import org.apache.ibatis.annotations.Param;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import org.apache.ibatis.annotations.Select;
import com.eshop.modules.order.vo.OrderDataVo;
import java.util.List;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Repository;
import com.eshop.modules.order.domain.StoreOrder;
import com.eshop.common.mapper.CoreMapper;

@Repository
public interface StoreOrderMapper extends CoreMapper<StoreOrder>
{
    @Select({ "SELECT sum(pay_price) as price,count(id) as count,DATE_FORMAT(create_time, '%m-%d') as time FROM store_order WHERE is_del = 0 AND paid = 1 AND refund_status = 0 GROUP BY DATE_FORMAT(create_time,'%Y-%m-%d') ORDER BY create_time DESC" })
    List<OrderDataVo> getOrderDataPriceList(final Page page);
    
    @Select({ "SELECT IFNULL(sum(pay_price),0)  FROM store_order ${ew.customSqlSegment}" })
    Double todayPrice(@Param("ew") final Wrapper<StoreOrder> wrapper);
    
    @Select({ "select IFNULL(sum(pay_price),0) from store_order where paid=1 and is_del=0 and refund_status=0 and uid=#{uid}" })
    double sumPrice(@Param("uid") final Long uid);
    
    @Select({ "SELECT COUNT(*) FROM store_order WHERE pay_time >= ${today}" })
    Integer countByPayTimeGreaterThanEqual(@Param("today") final int today);
    
    @Select({ "SELECT COUNT(*) FROM store_order WHERE pay_time < ${today}  and pay_time >= ${yesterday}" })
    Integer countByPayTimeLessThanAndPayTimeGreaterThanEqual(@Param("today") final int today, @Param("yesterday") final int yesterday);
    
    @Select({ "select IFNULL(sum(pay_price),0)  from store_order where refund_status=0 and is_del=0 and paid=1" })
    Double sumTotalPrice();
    
    @Select({ "SELECT IFNULL(sum(pay_price),0) as num,DATE_FORMAT(create_time, '%m-%d') as time  FROM store_order where refund_status=0 and is_del=0 and paid=1 and pay_time >= #{time} GROUP BY DATE_FORMAT(create_time,'%Y-%m-%d')  ORDER BY create_time ASC" })
    List<ChartDataDto> chartList(@Param("time") final Date time);
    
    @Select({ "SELECT count(id) as num,DATE_FORMAT(create_time, '%m-%d') as time  FROM store_order where refund_status=0 and is_del=0 and paid=1 and pay_time >= #{time} GROUP BY DATE_FORMAT(create_time,'%Y-%m-%d')  ORDER BY create_time ASC" })
    List<ChartDataDto> chartListT(@Param("time") final Date time);
}
